home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / debug.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  6.3 KB  |  184 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Provides debug utilities for Orca.  Debugging is managed by a debug
  5. level, which is held in the debugLevel field.  All other methods take
  6. a debug level, which is compared to the current debug level to
  7. determine if the content should be output.'''
  8. __id__ = '$Id: debug.py 3882 2008-05-07 18:22:10Z richb $'
  9. __version__ = '$Revision: 3882 $'
  10. __date__ = '$Date: 2008-05-07 14:22:10 -0400 (Wed, 07 May 2008) $'
  11. __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
  12. __license__ = 'LGPL'
  13. import traceback
  14. import pyatspi
  15. LEVEL_OFF = 10000
  16. LEVEL_SEVERE = 1000
  17. LEVEL_WARNING = 900
  18. LEVEL_INFO = 800
  19. LEVEL_CONFIGURATION = 700
  20. LEVEL_FINE = 600
  21. LEVEL_FINER = 500
  22. LEVEL_FINEST = 400
  23. LEVEL_ALL = 0
  24. debugLevel = LEVEL_SEVERE
  25. debugFile = None
  26. eventDebugLevel = LEVEL_FINEST
  27. eventDebugFilter = None
  28.  
  29. def printException(level):
  30.     '''Prints out information regarding the current exception.
  31.  
  32.     Arguments:
  33.     - level: the accepted debug level
  34.     '''
  35.     if level >= debugLevel:
  36.         println(level)
  37.         traceback.print_exc(100, debugFile)
  38.         println(level)
  39.     
  40.  
  41.  
  42. def printStack(level):
  43.     '''Prints out the current stack.
  44.  
  45.     Arguments:
  46.     - level: the accepted debug level
  47.     '''
  48.     if level >= debugLevel:
  49.         println(level)
  50.         traceback.print_stack(None, 100, debugFile)
  51.         println(level)
  52.     
  53.  
  54.  
  55. def println(level, text = ''):
  56.     '''Prints the text to stdout if debug is enabled.
  57.  
  58.     Arguments:
  59.     - level: the accepted debug level
  60.     - text: the text to print (default is a blank line)
  61.     '''
  62.     if level >= debugLevel:
  63.         if debugFile:
  64.             debugFile.writelines([
  65.                 text,
  66.                 '\n'])
  67.         else:
  68.             print text
  69.     
  70.  
  71.  
  72. def printObjectEvent(level, event, sourceInfo = None):
  73.     '''Prints out an Python Event object.  The given level may be
  74.     overridden if the eventDebugLevel is greater.  Furthermore, only
  75.     events with event types matching the eventDebugFilter regular
  76.     expression will be printed.
  77.  
  78.     Arguments:
  79.     - level: the accepted debug level
  80.     - event: the Python Event to print
  81.     - sourceInfo: additional string to print out
  82.     '''
  83.     if eventDebugFilter and not eventDebugFilter.match(event.type):
  84.         return None
  85.     level = max(level, eventDebugLevel)
  86.     text = 'OBJECT EVENT: %-40s detail=(%d,%d)' % (event.type, event.detail1, event.detail2)
  87.     println(level, text)
  88.     if sourceInfo:
  89.         println(level, '             %s' % sourceInfo)
  90.     
  91.  
  92.  
  93. def printInputEvent(level, string):
  94.     '''Prints out an input event.  The given level may be overridden
  95.     if the eventDebugLevel (see setEventDebugLevel) is greater.
  96.  
  97.     Arguments:
  98.     - level: the accepted debug level
  99.     - string: the string representing the input event
  100.     '''
  101.     println(max(level, eventDebugLevel), string)
  102.  
  103.  
  104. def printDetails(level, indent, accessible, includeApp = True):
  105.     '''Lists the details of the given accessible with the given
  106.     indentation.
  107.  
  108.     Arguments:
  109.     - level: the accepted debug level
  110.     - indent: a string containing spaces for indentation
  111.     - accessible: the accessible whose details are to be listed
  112.     - includeApp: if True, include information about the app
  113.     '''
  114.     if level >= debugLevel and accessible:
  115.         println(level, getAccessibleDetails(accessible, indent, includeApp))
  116.     
  117.  
  118.  
  119. def getAccessibleDetails(acc, indent = '', includeApp = True):
  120.     '''Returns a string, suitable for printing, that describes the
  121.     given accessible.
  122.  
  123.     Arguments:
  124.     - indent: A string to prefix the output with
  125.     - includeApp: If True, include information about the app
  126.                   for this accessible.
  127.     '''
  128.     if includeApp:
  129.         app = acc.getApplication()
  130.         if app:
  131.             string = indent + "app.name='%s' " % app.name
  132.         else:
  133.             string = indent + 'app=None '
  134.     else:
  135.         string = indent
  136.     stateSet = acc.getState()
  137.     states = stateSet.getStates()
  138.     state_strings = []
  139.     for state in states:
  140.         state_strings.append(pyatspi.stateToString(state))
  141.     
  142.     state_string = ' '.join(state_strings)
  143.     relations = acc.getRelationSet()
  144.     if relations:
  145.         relation_strings = []
  146.         for relation in relations:
  147.             relation_strings.append(pyatspi.relationToString(relation.getRelationType()))
  148.         
  149.         rel_string = ' '.join(relation_strings)
  150.     else:
  151.         rel_string = ''
  152.     if not acc.name:
  153.         pass
  154.     string += "name='%s' role='%s' state='%s' relations='%s'" % ('None', acc.getRoleName(), state_string, rel_string)
  155.     return string
  156.  
  157. import linecache
  158.  
  159. def traceit(frame, event, arg):
  160.     """Line tracing utility to output all lines as they are executed by
  161.     the interpreter.  This is to be used by sys.settrace and is for 
  162.     debugging purposes.
  163.    
  164.     Arguments:
  165.     - frame: is the current stack frame
  166.     - event: 'call', 'line', 'return', 'exception', 'c_call', 'c_return',
  167.              or 'c_exception'
  168.     - arg:   depends on the event type (see docs for sys.settrace)
  169.     """
  170.     if event == 'line':
  171.         lineno = frame.f_lineno
  172.         filename = frame.f_globals['__file__']
  173.         if filename.endswith('.pyc') or filename.endswith('.pyo'):
  174.             filename = filename[:-1]
  175.         
  176.         name = frame.f_globals['__name__']
  177.         if name == 'gettext' and name == 'locale' and name == 'posixpath' or name == 'UserDict':
  178.             return traceit
  179.         line = linecache.getline(filename, lineno)
  180.         println(LEVEL_ALL, 'TRACE %s:%s: %s' % (name, lineno, line.rstrip()))
  181.     
  182.     return traceit
  183.  
  184.